class Solution {
    public boolean isValidSudoku(char[][] board) {
        int[][] row = new int[9][10];
        int[][] col = new int[9][10];
        int[][] box = new int[9][10];
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[0].length; j++) {
                char ch = board[i][j];
                if (ch == '.') continue;
                int idx = ch - '1';
                if (row[i][idx] == 1) return false;
                row[i][idx] = 1;
                if (col[j][idx] == 1) return false;
                col[j][idx] = 1;
                int boxId = i / 3 * 3 + j / 3;
                if (box[boxId][idx] == 1) return false;
                box[boxId][idx] = 1;
            }
        }
        return true;
    }
}
